package com.lzy.cloud.shop.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.shop.dto.ShopDto;
import com.lzy.cloud.shop.entity.Shop;
import com.lzy.cloud.shop.mapper.ShopMapperExt;
import com.lzy.cloud.shop.service.ShopService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopServiceImpl implements ShopService {

    @Autowired
    private ShopMapperExt shopMapperExt;

    @Override
    public PageInfo selectAllShop(Pager pager, ShopDto shopDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ShopDto> permissionDtoList = shopMapperExt.selectShopList(shopDto);
        return new PageInfo(permissionDtoList);
    }

    @Override
    public Long addShop(ShopDto shopDto) {
        Shop shop = DozerUtils.map(shopDto, Shop.class);
        return shopMapperExt.insertSelective(shop)>0?shop.getId():null;
    }

    @Override
    public Boolean updateShop(ShopDto shopDto) {
        return shopMapperExt.updateByPrimaryKeySelective(DozerUtils.map(shopDto,Shop.class)) > 0;
    }

    @Override
    public ShopDto selectById(Long id) {
        return  DozerUtils.map(shopMapperExt.selectByPrimaryKey(id), ShopDto.class);
    }

    @Override
    public Boolean deleteById(Long id) {
        return shopMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public String selectName(Long id) {
        return shopMapperExt.selectName(id);
    }

    @Override
    public List<ShopDto> selectByIds(String ids) {
        return shopMapperExt.selectByIds(ids);
    }

    @Override
    public PageInfo<ShopDto> selectByCategoryId(Pager pager,Integer categoryId, ShopDto shopDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ShopDto> shopDtoList = shopMapperExt.selectByCategoryId(categoryId,shopDto);
        return new PageInfo<>(shopDtoList);
    }
}
